/**
 * 接诊病人页签js
 */
$(document).ready(function() 
	{
	    configCurrentDate();
	}
);

function configCurrentDate() {
	var dl1 = new Date();
	dl1.setDate(dl1.getDate() - Number(valueArr['p_100_105002_149']));
	$("#dl1_jiezhen").val(dl1.Format("yyyy-MM-dd"));
	$("#dl2_jiezhen").val(new Date().Format("yyyy-MM-dd"));
}

// 门诊医生系统科室列表
function deptList_jiezhen() {
	$.ajax({
		url : rootUrl + "/patientsearch/finddepartments",
		type : "get",
		dataType : 'json',
		data:{"bce01":bce01,"bck01":yiyuanId},
		async:false,
		success : function(data) {
			debugger;
			departmentList = data.list;
			var html = "";
			for (var i = 0; i < departmentList.length; i++) {
				html = html + "<option value=\"" + departmentList[i]["bck01"]
						+ "\">" + departmentList[i]["bck03"] + "</option>";
			}
			//接诊页签
			$("#departmentList_jiezhen").html(html);
			$('#departmentList_jiezhen').select2(
					{
						placeholder : '请选择科室',
						allowClear : true
					});
			
			var bck01Obj = $("#departmentList_jiezhen");
			bck01 = $(bck01Obj).find("option:selected").val();
			if (typeof (bck01) == "undefined") {
				bck01 = $(bck01Obj).find("option:first").val();
			}
			jiezhenInit();
		}
	});
}

/**
 * 刷新候诊列表
 */
function refreshJiezhenList()
{
//	$(".header-content-left").empty();
	debugger;
	jiezhenInit();//加载候诊病人列表
}

/**
 * 候诊科室列表的onchange事件
 */
function refreshBck01_jiezhen()
{
	var bck01Obj = $("#departmentList_jiezhen");
	bck01 = $(bck01Obj).find("option:selected").val();
	if (typeof (bck01) == "undefined") {
		bck01 = $(bck01Obj).find("option:first").val();
	}
	refreshJiezhenList();
}


/**
 * 双击接诊病人，直接新开处方（或者书写病历）
 * @param tableId
 */
function zhijiexinkai_jiezhen()
{
	//reloadPatientInfo_content(vac01);
	if (vac01) {
		reloadPatientInfo_jiezhen(vac01_houzhen);
		// 获取选中行的值
		$.ajax({
			url : rootUrl + "/clinicalreceptiontransfer/clinicvac1update",
			data : {
				lVAA07 : vac01,
				lVAA01 : vaa01,
				lSign : 0,
				lBCK01 : bck01,
				lBCE01 : 1,
				lBCE02 : '8080',
				lBCE03 : 1
			},
			type : "post",
			dataType : 'json',
			success : function(data) {
				refreshHouzhenList();
				refreshJiezhenList();
				
				// 接诊后自动进入新开页面
				var temp = valueArr["p_100_105002_393"];
				if(temp=="1")
				{
					$('#new_order_list a[href="#Emr"]').trigger("click");	
				}
				else if(temp=="2")
				{
					$('#new_order_list a[href="#NewAdvice"]').trigger("click");
				}	
			}
		});
	} else {
		layer.msg("请选择要接诊的病人", {
			time : 2000,
			icon : 0,
			skin: 'layui-layer-msg0'
		});
	}
}

/**
 * 弹出病人医嘱页面
 */
function patientAdvice()
{
	if (vaa01) {
		var index = layer.open({
			type : 2,
			title : '医嘱列表  ',
			area : [ "95%", "95%" ],
			shade : 0.3,
			maxmin : true,
			content :myurl+"/neworder.jsp",

		});
	} else {
		layer.msg("请选择就诊病人", {
			time : 2000,
			icon : 0,
			skin: 'layui-layer-msg0'
		});
	}
}


//病人信息按钮控制
function seeMoreInfoEvent(){
	if(vaa01||vaa01_houzhen){
		var flag = $(".three-column").find(".main-header").hasClass('br_expanded');
		if(flag){
			$(".three-column").find(".main-header").removeClass('br_expanded');
			$(".three-column").find(".main-header").css('height','40px');
			$(".three-column").find('.more-info-text').text('更多');
			$(".three-column").find(".btn-transparent").find('.caret').removeClass('caret-top');
			$('.three-column-conent').css('top','40px');
			$(".patientInfo_more").addClass("hidden");
			$(".header-content-left ul li").removeAttr('style');
			$(".header-content-left ul li").css('margin-right','30px');
			
		}else{
			$(".three-column").find(".main-header").addClass('br_expanded');
			$(".three-column").find(".main-header").css('height','110px');
			$(".three-column").find('.more-info-text').text('收起');
			$(".three-column").find(".btn-transparent").find('.caret').addClass('caret-top');
			$('.three-column-conent').css('top','115px');
			$(".patientInfo_more").removeClass("hidden");
			$(".header-content-left ul li").css('width','160px');
			$(".header-content-left ul li").css('margin-right','0px');
		}
	}
}


//转诊
function zhuanzhen() {
	var that = this;
	 var id = $("#jiezhenList").jqGrid('getGridParam','selrow');//根据点击行获得点击行的id（id为jsonReader: {id: "id" },）
     var rowData = $("#jiezhenList").jqGrid("getRowData",id);//根据上面的id获得本行的所有数据
	if (id) {
		$.ajax({
			url : rootUrl + "/patientsearch/finddepartments",
			data:{"bce01":bce01},
			type : "get",
			dataType : 'json',
			success : function(data) {
				that.laytplUrl(myurl + "/module/menzhen_zhuanzhen.html",
						data, function(data, html) {
							var index = layer.open({
								type : 1,
								// scrollbar : false,
								title : "病人院内转诊",
								area : [ "400px", "270px" ],
								shade : 0.1,
								// maxmin : true,
								content : html,
								closeBtn : 1,
								success : function() {
									$("select").select2({
										language: "zh-CN"
									});
									
									$("#remove_action_zz").on("click",function(){
										layer.close(index);
									})
									loadBce1();
								}
							})

						});
			}
		});

	} else {
		layer.msg("请选择要转诊的接诊病人", {
			time : 2000,
			icon : 0,
			skin: 'layui-layer-msg0'
		});
	}

}


/**
 * 院内转诊
 */
function clinic_change_bck1() {
	var url = rootUrl + "/clinicalreceptiontransfer/clinicchangebck1";
	var params = {};
	var id = $("#jiezhenList").jqGrid('getGridParam','selrow');//根据点击行获得点击行的id（id为jsonReader: {id: "id" },）
    var rowData = $("#jiezhenList").jqGrid("getRowData",id);//根据上面的id获得本行的所有数据
	params.lVAC01 = rowData.vac01;
	params.lBCK01 = $("#zhuanrukeshi").find("option:selected").val();
	params.lBCE01 = $("#jiezhenyishi").find("option:selected").val();
	params.lBCE03 = $("#jiezhenyishi").find("option:selected").text();
	params.lBCE01A = bce01;
	params.BAS02 = 1;
	$.post(url, params, function(data) {
		if (data.result == "Success") {
			layer.msg("转诊成功！", {
				time : 2000,
				icon : 1,
				skin: 'layui-layer-msg1'
			});
			layer.closeAll();// 关闭弹出层
			refreshJiezhenList();
		} else {
			layer.msg(data.resultMsg, {
				time : 2000,
				icon : 2,
				skin: 'layui-layer-msg2'
			});
		}
	});
}

//根据bck01加载医师列表
function loadBce1() {
	var bck01 = $("#zhuanrukeshi").find("option:selected").val();
	var url = rootUrl + "/treatment/loadBce1";
	var params = {};
	params.bck01 = bck01;
	$.get(url, params, function(data) {
		var list = data.list;
		for (var i = 0; i < list.length; i++) {
			var option = $("<option>").attr('value', list[i]['bce01']).text(
					list[i]['bce03']);
			$("#jiezhenyishi").empty().append(option);
		}
	});
}


